{% extends "layout.html" %}

{% block extra_css %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/user_profile.css') }}">
{% endblock %}

{% block content %}
<div class="profile-container">
    <h1>个人资料</h1>

    {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            <div class="flash-messages">
                {% for category, message in messages %}
                    <div class="alert alert-{{ category }}">{{ message }}</div>
                {% endfor %}
            </div>
        {% endif %}
    {% endwith %}

    <form method="POST" action="{{ url_for('profile.profile') }}" class="profile-form">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" id="username" name="username" value="{{ user.username }}" required>
        </div>

        <div class="form-group">
            <label for="email">电子邮箱</label>
            <input type="email" id="email" name="email" value="{{ user.email }}" required>
        </div>

        <div class="form-group">
            <label for="password">新密码 (留空则不修改)</label>
            <input type="password" id="password" name="password">
            <small class="form-text">至少8个字符，包含字母和数字</small>
        </div>

        <div class="form-group">
            <label for="confirm_password">确认新密码</label>
            <input type="password" id="confirm_password" name="confirm_password">
        </div>

        <div class="form-actions">
            <button type="submit" class="btn btn-primary">保存更改</button>
            <a href="{{ url_for('hikes.index') }}" class="btn btn-secondary">返回首页</a>
        </div>
    </form>

    <div class="profile-stats">
        <h3>账户信息</h3>
        <p>用户ID: {{ user.id }}</p>
        <p>注册时间: {{ user.get('registration_time', '未知') }}</p>
        <p>最后登录: {{ user.get('last_login_time', '未知') }}</p>
    </div>
</div>
{% endblock %}